package leetcode;

import java.util.*;

public class LeetCode49 {
    public List<List<String>> groupAnagrams(String[] strs) {
        List<List<String>> result = new ArrayList<>();
        Map<String, List<String>> map = new HashMap<>();
        for (String str : strs) {
            char[] chars = str.toCharArray();
            Arrays.sort(chars);
            String key = String.valueOf(chars);
            if (map.containsKey(key))
                map.get(key).add(str);
            else {
                List<String> list = new ArrayList<>();
                list.add(str);
                map.put(key, list);
                result.add(list);
            }
        }
        return result;
    }
//------------------------------------------------------------------
}
